// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import "@/assets/index.css"

//导入elementui-js
import ElementUI from 'element-ui'
//导入elementui-css
import 'element-ui/lib/theme-chalk/index.css'
//导入 axios
import axios from 'axios'
//配置公共路径
axios.defaults.baseURL="http://localhost:8888/api/private/v1"

// 请求的拦截器
axios.interceptors.request.use(function (config) {
    // 在请求发送之前
    //在拦截器添加请求头
    //endsWith字符串以什么结尾
    if(!config.url.endsWith("/login")){
    	config.headers['Authorization'] = localStorage.getItem('token')
    }
//  console.log("请求拦截器",config)
    return config;
  });

// 响应拦截器
axios.interceptors.response.use(function (response) {
    // Do something with response data
    console.log("响应拦截器",response)
    if(response.data.meta.status === 401){
    	router.push('/login')
    }
    return response;
  });




Vue.prototype.$http=axios


//安装插件
Vue.use(ElementUI)
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
